//
//  CZStatus.swift
//  微博08
//
//  Created by 1 on 16/3/10.
//  Copyright © 2016年 cjf. All rights reserved.
//

import UIKit

class CZStatus: NSObject {
    // 微博创建时间
    var created_at: String?
    
    // 微博ID
    var id: Int64 = 0
    
    // 微博内容
    var text: String?
    
    // 微博来源
    var source: String?
    
    // 微博配图
    var pic_urls: [[String: AnyObject]]?

    // 转发数
    var reposts_count: Int = 0
    
    // 评论数
    var comments_count: Int = 0
    
    // 表态数
    var attitudes_count: Int = 0
    
    // 用户模型
    var user: CZUser?
    
    // 字典转模型
    init(dict: [String: AnyObject]) {
        super.init()

        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        // 判断key == user 时，将value字典转成模型,并赋值给user属性
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                //value是一个字典，字典转模型
                user = CZUser(dict: dict)
            }
            // 要return,不要走父类的将字典赋值给user属性
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    // 打印
    override var description: String {
        let keys = ["created_at", "id", "text", "source", "pic_urls", "reposts_count", "comments_count", "attitudes_count", "user"]
        
        // \t: 制表符= tab键
        return "\n\t微博模型: \(dictionaryWithValuesForKeys(keys).description)"
    }
}
